<%= render :partial => "shared/code_necessary" %>
<%= javascript_include_tag "jquery.fancybox.js " %>
<%= javascript_include_tag "jquery.validate.js" %>
<%= stylesheet_link_tag "fancybox/jquery.fancybox.css" %>
<%= stylesheet_link_tag "jquery-validate.css" %>
<script type="text/javascript">
  $(document).ready(function() {
      $("a.upload_image").fancybox({
        'overlayOpacity'	:	0.1,
        'overlayColor'		:	'#FFF',
        'zoomSpeedIn'		:	500,
        'zoomSpeedOut'		:	500
        });

         $("#name").validate({
             expression: "if (VAL) return true; else return false;",
             message: "请留下您的大名,谢谢",
             live: false
         });
         $("#email").validate({
             expression: "if (VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;",
             message: "请写真实的email",
             live: false
         });

         $("#message").validate({
             expression: "if (VAL = '') return true; else return false;",
             message: "大哥，写点东西吧，谢谢",
             live: false
         });

  var initialWidth = $('#mid-content pre:first').width(); //store the initial width of code-boxes for the reset on mouse out
  $('pre').live("hover",function() { //on mouse over
    if($(this).height() > $(this).children().height()) { //if <pre> is higher than <code>
      var openSpace = Math.round(($('body').width() - initialWidth) / 2 - 10); //calculate the space to the right with a margin-right of 10px
      if($(this).width() == initialWidth) { //start animation only when we are at starting point (initial width)
        $(this).animate({ width : initialWidth + openSpace }, 'fast'); //increase the width with animation
      }else{
        $(this).animate({ width : initialWidth }, 'fast'); //reset to initial width with animation
      }
    }
  });
         
});




</script>
<div class='post'>
    <h2><%= @article.title %></h2>
</div>
<div class="content">
    <%= @article.content.bbcode_to_html %>
</div>
<% if @article.upload_files.size > 0 %>
    <div class="attachbox">
        <% @article.upload_files.each do |upload_file| %>
            <div style="width:30px;float:left;padding:10px;">
                <a rel="group" href="<%= upload_file.attachment.url %>" title="<%= upload_file.comment %>" class="upload_image">
                    <img height="40" width="40" src="<%= upload_file.attachment.url %>"/>
                </a>
            </div>
        <% end %>
    </div>
<% end %>
<br/>
<p class="tags" style="width:100%">
    <%= @article.categories.collect{|category| link_to(category.name,category_path(category))}.join(",") %>
</p>

<br/>
<br/>
<div id="mid-content" role="main">
    <div id="post-extra-content">
        <div  style="display: block;" style="width:98%">
            <ol id="comments">
                <% @article.comments.each_with_index do |comment,index| %>
                    <li id="comment-<%= index+1 %>" class="comment byuser comment-author-admin bypostauthor odd alt thread-even depth-1 with-avatars">
                    <div class="details admincomment">
                        <p class="head">
                        <span class="info">
                            <a href="#comment-<%= index + 1 %>">#<%= index + 1 %></a> by <b id="commentauthor-<%= index + 1 %>"><%= comment.name %></b> on <%= comment.created_at.to_s(:cn_date) %>
                        </span>
                        </p>
                        <!-- comment contents -->
                        <div class="text">
                            <div id="commentbody-<%= index + 1 %>">
                                <p>
                                <%= comment.content %>
                                </p>
                            </div>
                        </div>
                        <!-- /comment contents -->
                    </div>
                    </li>
                <% end %>
            </ol>
        </div>

    </div>

</div>




<% form_tag({:action => "add_comment"},{:method => :post,:style => "width:80%"}) do %>
    <p><label for="name">Name:</label><br/>
    <input type="text" value="" id="name" name="name"/><br/></p>

    <p><label for="email">Email:</label><br/>

    <input type="text" value="" id="email" name="email"/><br/></p>
    <p><label for="message">Message:</label><br/>
    <textarea id="message" name="message" rows="11" cols="60"></textarea><br/></p>
    <p>
    <input type="submit" value="Send" class="formbutton" name="send"/>
    <%= hidden_field_tag "id",@article.id %>   
    </p>
<% end %>
